package com.csdn;

import java.io.IOException;
import java.util.List;

import org.apache.log4j.LogManager;
 

public class RestError {

	private static org.apache.log4j.Logger log = LogManager.getLogger(RestError.class);


	public static void main(String[] args) throws IOException {
	       System.setProperty("http.maxRedirects", "50");
			System.getProperties().setProperty("proxySet", "true");
		//	System.getProperties().setProperty("http.proxyHost", "180.97.250.86");
			System.getProperties().setProperty("http.proxyHost", "101.96.9.136");
			System.getProperties().setProperty("http.proxyPort", "80");

		
		
       int count= 0;
		List<String> fileName = GetFileName.getRestErrorFile();
		for (String txtPath : fileName) {
			List<String> urls = getErrorRestURL.readTxtLine(txtPath);
			for (String url : urls) {
				try {
					log.info("重新刷新博客人数据："+url);
					System.out.println(url);
				  	Main.getblog(url);
				} catch (RuntimeException e) {
					log.error("没数据："+url);
					continue;
				} catch (Exception e) {
					 log.error("没爬取："+url +" :" + e.getMessage());
					 count ++;
						log.error("重试"+count+" url:"+url);
						log.error(e.getMessage());
						System.setProperty("http.maxRedirects", "50");
						System.getProperties().setProperty("proxySet", "true");
						System.getProperties().setProperty("http.proxyHost", "111.13.2.138");
						System.getProperties().setProperty("http.proxyPort", "80");	   
						count = 0;
						if(count == 2){
							System.setProperty("http.maxRedirects", "50");
							System.getProperties().setProperty("proxySet", "true");
							System.getProperties().setProperty("http.proxyHost", "183.222.102.105");
							System.getProperties().setProperty("http.proxyPort", "80");
				
						}else if(count == 3){
							System.setProperty("http.maxRedirects", "50");
							System.getProperties().setProperty("proxySet", "true");
							System.getProperties().setProperty("http.proxyHost", "183.222.102.104");
							System.getProperties().setProperty("http.proxyPort", "80");
						}else if(count == 4){
							System.setProperty("http.maxRedirects", "50");
							System.getProperties().setProperty("proxySet", "true");
							System.getProperties().setProperty("http.proxyHost", "183.222.102.106");
							System.getProperties().setProperty("http.proxyPort", "80");
						}else{
							System.setProperty("http.maxRedirects", "50");
							System.getProperties().setProperty("proxySet", "true");
							System.getProperties().setProperty("http.proxyHost", "111.13.2.138");
							System.getProperties().setProperty("http.proxyPort", "80");	   
							count = 0;
						} 
					 continue;
				}
			}
		}
		
	}

}
